package com.itdfq.mybatisplus.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @Author GocChin
 * @Date 2021/5/18 19:16
 * @Blog: itdfq.com
 * @QQ: 909256107
 * @Descript:
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    //添加时填充
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.strictInsertFill(metaObject,"createTime",Date.class,new Date());
        this.strictInsertFill(metaObject,"updateTime",Date.class,new Date());
        this.strictInsertFill(metaObject,"version",Integer.class,1);
        this.strictInsertFill(metaObject,"deleted",Integer.class,0);

    }

    //修改是填充
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        this.strictUpdateFill(metaObject,"updateTime",Date.class,new Date());
    }


}